package com.friend.chat.page.vm

import androidx.lifecycle.MutableLiveData
import com.friend.chat.net.BaseResult
import com.friend.chat.base.BasicViewModel
import com.friend.chat.page.bean.UserBean
import com.friend.chat.utils.SPUtils

/**
 * @des
 * @author batie fancy
 * @date 2022/12/31
 */
class LoginViewModel: BasicViewModel()  {
    val userResponse by lazy { MutableLiveData<BaseResult<UserBean>>() }

    fun loginByPass(username:String,password:String) {
        netWorkJob(
            successResult = {
                val data = mRepository.loginByPass(username,password)
                if (!data.isOk()) {
                    toast(data.message)
                } else {
                    SPUtils.getInstance().putObject("user",data.data)
                    userResponse.value = data
                }
            },
            errorResult = {
                toast("错误")
            }
        )
    }
}